<?php
/**
 * 付款
 * Enter description here ...
 * @author nijn
 *
 */
class PayAction extends CAction {
	public $modelName = '';

	public function run($id) {
		$c = $this->controller;
		$adminUser = Yii::app()->adminUser;
		$model = Order::model()->findByAttributes(array(
			'id' => $id,
			'worker_id' => $adminUser->id
		));
		if (!is_object($model)) $c->redirect(Yii::app()->createUrl('misc/error404',array('msg'=>'该数据不存在')));

		$pay = is_object($model->pay) ? $model->pay : new PaymentBill();
		$payObj = Yii::app()->pay->{$model->pay_type};
		$attributes = array(
			'payment_id' => $id,
			'outer_order_id' => $payObj->tid,
			'user_id' => $adminUser->id,
			'user_name' => CHtml::value($adminUser->worker, 'profile.nickname'),
			'money' => CHtml::value($model, 'total'),
			'pay_time' => date('Y-m-d H:i:s'),
			'status' => 0,
		);
		$pay->attributes = $attributes;
		if ($pay->save())
			$payObj->topay(CHtml::value($model, 'items.goods.fullTitle'), CHtml::value($model, 'total'));
	}
}